package org.example;

import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Random;

/**
 * @Author: duhang
 * @Date: 2022/8/25
 * @Description:
 **/
public class TestExcel {
    public static void main(String[] args) throws IOException {


        //得到数据后，选择要写入的文件，进行写入，也可以写入原来的文件，这里选择新建文件写入
        //读取excel
        String filePathres = "G:\\Desktop\\category.xlsx"; // 写入 文件的目录

        XSSFWorkbook wb = new XSSFWorkbook();
        XSSFSheet sheetAt1 = wb.createSheet("res");
        FileOutputStream fileOutputStream = new FileOutputStream(filePathres);

        Random random = new Random();
        for (int i = 0; i < 780; i++) {

            //创建一行
            XSSFRow row = sheetAt1.createRow(i);

            //生成随机数
            int num = random.nextInt(4);
            String ss = "";
            if(num == 0){
                ss = "新一代信息技术产业、新材料产业、节能环保产业";
            }else if(num == 1){
                ss = "新材料产业、高端装备制造产业 新一代信息技术产业";
            }else if(num == 2){
                ss = "新能源产业、新能源环保产业";
            }else{
                ss = "高端装备制造产业、节能环保产业、 新一代信息技术产业";
            }
            //公司名称
            XSSFCell cell1 = row.createCell(0);
            cell1.setCellValue(ss);


        }
        fileOutputStream.flush();
        wb.write(fileOutputStream);
        wb.close();
        fileOutputStream.close();

    }

}
